package com.blog.effective.note5;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * 测试类.
 *
 * @author 张俊强~.
 * @date 2017/11/02-09:06.
 */
public class Person {

    private final Date birthDate;

    public static final Date BoomStart;
    public static final Date BoomEnd;

    public Person(Date birthDate) {
        this.birthDate = birthDate;
    }

    static {
        Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

        gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
        BoomStart = gmtCal.getTime();

        gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
        BoomEnd = gmtCal.getTime();

    }

    public boolean isPost90s() {

        return birthDate.compareTo(BoomStart) >= 0 &&
                birthDate.compareTo(BoomEnd) < 0;

    }

//    public boolean isPost90sMethod1() {
//
//        Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
//
//        gmtCal.set(1990, Calendar.JANUARY, 1, 0, 0, 0);
//
//        Date post90sStart = gmtCal.getTime();//90后开始时间[包含]
//
//        gmtCal.set(2000, Calendar.JANUARY, 1, 0, 0, 0);
//
//        Date post90sEnd = gmtCal.getTime();//90后结束时间[不包含]
//        //compareTo()函数来比较当前Person是不是90后
//        return birthDate.compareTo(post90sStart) >= 0 &&
//                birthDate.compareTo(post90sEnd) < 0;
//
//    }

}

